package cn.wolfcode.trip.app.web.controller;

import cn.wolfcode.trip.app.util.UserContext;
import cn.wolfcode.trip.base.domain.Chat;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.query.ChatQueryObject;
import cn.wolfcode.trip.base.service.IChatService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/chat")
public class ChatController {
    @Autowired
    private IChatService chatService;

    @PostMapping
    public Object send(Chat chat) {
        //设置当前登录用户
        chat.setUserId(UserContext.getCurrentUser().getId());
        chatService.insert(chat);
        return null;
    }
    @GetMapping
    public Object show(ChatQueryObject qo) {
        qo.setId(UserContext.getCurrentUser().getId());
        //设置当前登录用户
        PageInfo pageInfo=chatService.showChatContent(qo);
        return pageInfo;
    }
    @GetMapping("/number")
    public Object ChatNumber() {
        ChatQueryObject qo = new ChatQueryObject();
        //设置查询条件
        qo.setFriendId(UserContext.getCurrentUser().getId());
        //设置当前登录用户
        Map<String,Integer> map=chatService.listChatNumber(qo);
        return map;
    }
}
